/**
 * 车辆基本信息
*
*/
var express = require('express');
var request = require('request');

var url = require('url');
var qstr = require("querystring");
var fs = require("fs");
var pro = require('../../property/cuspro');
var auth = require('../../auth/auth');
var util = require('../../util/commonutil');
var router = express.Router();
// var querystring = require('querystring');

router.get('/total', function(req, res, next) {
   auth.checkAuth(req, res, next);
   res.render('report/total',{serverurl:pro.serveraddr});
});
//运行统计
router.get('/carwork', function(req, res, next) {
    auth.checkAuth(req, res, next);
    res.render('report/carwork',{serverurl:pro.serveraddr});
});
router.get('/carworktime', function(req, res, next) {
    auth.checkAuth(req, res, next);
    res.render('report/carworktime',{serverurl:pro.serveraddr});
});
router.get('/warning', function(req, res, next) {
    auth.checkAuth(req, res, next);
    res.render('report/warning',{serverurl:pro.serveraddr});
});
router.get('/carnowork', function(req, res, next) {
    auth.checkAuth(req, res, next);
    res.render('report/carnowork',{serverurl:pro.serveraddr});
});
router.get('/caraction', function(req, res, next) {
    auth.checkAuth(req, res, next);
    res.render('report/caraction',{serverurl:pro.serveraddr});
});
router.get('/fence', function(req, res, next) {
    auth.checkAuth(req, res, next);
    res.render('report/fence',{serverurl:pro.serveraddr});
});
router.get('/business', function(req, res, next) {
    auth.checkAuth(req, res, next);
    res.render('report/business',{serverurl:pro.serveraddr});
});
router.get('/basecarreport', function(req, res, next) {
    auth.checkAuth(req, res, next);
    res.render('report/basecarreport',{serverurl:pro.serveraddr});
});
router.get('/totallist', function(req, res){
   // var pathname = url.parse(req.url).pathname;  //pathname => list
   //
   // var arg = url.parse(req.url, true).query;   //arg1 => {name:'a',id:'5'}
   //  var query=req.query;//参数
   // request({
   //     url: pro.serveraddr+'/report/totallist',
   //      method: "POST",
   //      qs: arg
   //  }, function(error, response, body) {
   //      if (!error && response.statusCode == 200) {
   //          var data=JSON.parse(body);
   //          if(data && data.success){
   //              res.json(data);
   //          }else {
   //              console.log("error= " + data.msg );
   //              res.json(data.msg);
   //          }
   //
   //
   //
   //      }
   //  });
});
router.get('/carworklist', function(req, res, next) {
    auth.checkAuth(req, res, next);
     var pathname = url.parse(req.url).pathname;  //pathname => list

     var arg = url.parse(req.url, true).query;   //arg1 => {name:'a',id:'5'}
     var query=req.query;//参数
     request({
         url: pro.serveraddr+'/total/listTotalRun',
         method: "POST",
         qs: arg
     }, function(error, response, body) {
         if (!error && response.statusCode == 200) {
             var data=JSON.parse(body);
             if(data && data.success){
                 res.json(data);
             }else {
                 console.log("error= " + data.msg );
                 res.json(data.msg);
             }



         }
     });
});
router.get('/carworkchart', function(req, res, next) {
    auth.checkAuth(req, res, next);
     var pathname = url.parse(req.url).pathname;  //pathname => list

     var arg = url.parse(req.url, true).query;   //arg1 => {name:'a',id:'5'}
     var query=req.query;//参数
     request({
         url: pro.serveraddr+'/total/listTotalRunChart',
         method: "POST",
         qs: arg
     }, function(error, response, body) {
         if (!error && response.statusCode == 200) {
             var data=JSON.parse(body);
             if(data ){
                 res.json(data);
             }else {
                 console.log("error= " + data.msg );
                 res.json(data.msg);
             }



         }
     });
});
// 区域统计
router.get('/fencechart', function(req, res, next) {
    auth.checkAuth(req, res, next);
     var pathname = url.parse(req.url).pathname;  //pathname => list

     var arg = url.parse(req.url, true).query;   //arg1 => {name:'a',id:'5'}
     var query=req.query;//参数
     request({
         url: pro.serveraddr+'/report/fencechart',
         method: "POST",
         qs: arg
     }, function(error, response, body) {
         if (!error && response.statusCode == 200) {
             var data=JSON.parse(body);
             if(data ){
                 res.json(data);
             }else {
                 console.log("error= " + data.msg );
                 res.json(data.msg);
             }



         }
     });
});
router.get('/warningCharts', function(req, res, next) {
    auth.checkAuth(req, res, next);
//    var categories=['部门-01', '部门-02', '部门-03'];
////        var data=[{
////            name: '车辆-01',
////            data: [7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6]
////        }];
//    var cdata=[{
//        name: '行驶里程',
//        data: [49.33, 71.5, 106.4]
//    }, {
//        name: '路线里程',
//        data: [83.6, 78.8, 98.5]
//    }, {
//        name: '行驶次数',
//        data: [48.9, 38.8, 39.3]
//    }, {
//        name: '路线次数',
//        data: [42.4, 33.2, 34.5]
//    }];
//
//    var data={"success":true,"categories":categories,"chartDate":cdata}

    // var res= {"success":true};
    //res.json(data);

//     var rows=[{"id":1,"baseCarNo":"鲁123","warningDate":"2017-04-05 12:12:00",
//        "deptName":"市政府","elType":"对象类型-01","warningType":1,
//        "empName":"王工","type":1,
//        "memo":"山东省青岛市高新区松园路-010号"
//     }];
//     var data={"msg":"","recordsFiltered":10,"success":true,"obj":null,"draw":1,"rows":rows,"recordsTotal":10}
//
//     res.json(data);
     var pathname = url.parse(req.url).pathname;  //pathname => list

     var arg = url.parse(req.url, true).query;   //arg1 => {name:'a',id:'5'}
     var query=req.query;//参数
    var sid = auth.getSessionID(req, res, next);
    arg.sid=sid;
     request({
         url: pro.serveraddr+'/report/warninghome',
         method: "POST",
         qs: arg
     }, function(error, response, body) {
         if (!error && response.statusCode == 200) {
             var data=JSON.parse(body);
             if(data ){
                 res.json(data);
             }else {
                 console.log("error= " + data.msg );
                 res.json(data.msg);
             }



         }
     });
});
router.get('/carworktimelist', function(req, res, next) {
    auth.checkAuth(req, res, next);

    var pathname = url.parse(req.url).pathname;  //pathname => list

    var arg = url.parse(req.url, true).query;   //arg1 => {name:'a',id:'5'}
    var query=req.query;//参数
    request({
        url: pro.serveraddr+'/report/carworktimelist',
        method: "POST",
        qs: arg
    }, function(error, response, body) {
        if (!error && response.statusCode == 200) {
            var data=JSON.parse(body);
            if(data && data.success){
                res.json(data);
            }else {
                console.log("error= " + data.msg );
                res.json(data.msg);
            }



        }
    });
});
router.get('/warninglist', function(req, res, next) {


    auth.checkAuth(req, res, next);
    // var data={"msg":"","recordsFiltered":3,"success":true,"obj":null,"draw":1,
    //     "rows":[
    //         {"id":1,"baseCarNo":"鲁xiaofan","deptName":0.0,"userName":"刘明","runTime":"超速","runNum":"2016-06-24 15:34:55","runMile":"国道104超速","lineNum":"已处理"},
    //         {"id":2,"baseCarNo":"鲁xiaofan1","deptName":0.0,"userName":"张三","runTime":"偏离路线","runNum":"2016-06-24 15:34:55","runMile":"偏离工作线路1","lineNum":"未处理"}
    //     ],
    //     "recordsTotal":3};
    // res.json(data);
    var pathname = url.parse(req.url).pathname;  //pathname => list

    var arg = url.parse(req.url, true).query;   //arg1 => {name:'a',id:'5'}
    var query=req.query;//参数
    request({
        url: pro.serveraddr+'/report/warninglist',
        method: "POST",
        qs: arg
    }, function(error, response, body) {
        if (!error && response.statusCode == 200) {
            var data=JSON.parse(body);
            if(data && data.success){
                res.json(data);
            }else {
                console.log("error= " + data.msg );
                res.json(data.msg);
            }



        }
    });
});
router.get('/carnoworklist', function(req, res, next) {


    auth.checkAuth(req, res, next);

    var pathname = url.parse(req.url).pathname;  //pathname => list

    var arg = url.parse(req.url, true).query;   //arg1 => {name:'a',id:'5'}
    var query=req.query;//参数
    request({
        url: pro.serveraddr+'/total/listTotalRunofCar',
        method: "POST",
        qs: arg
    }, function(error, response, body) {
        if (!error && response.statusCode == 200) {
            var data=JSON.parse(body);
            if(data && data.success){
                res.json(data);
            }else {
                console.log("error= " + data.msg );
                res.json(data.msg);
            }



        }
    });
});
router.get('/caractionlist', function(req, res, next) {
    auth.checkAuth(req, res, next);
    // var data={"msg":"","recordsFiltered":3,"success":true,"obj":null,"draw":1,
    //     "rows":[
    //         {"id":1,"baseCarNo":"鲁xiaofan","deptName":0.0,"userName":"刘明","runTime":"2016-06-26 13:28:10","runNum":"国道105","lineNum":"140"},
    //         {"id":2,"baseCarNo":"鲁xiaofan","deptName":0.0,"userName":"刘明","runTime":"2016-06-26 17:28:10","runNum":"红旗大街北","lineNum":"90"}
    //     ],
    //     "recordsTotal":3};
    // res.json(data);



    var pathname = url.parse(req.url).pathname;  //pathname => list

    var arg = url.parse(req.url, true).query;   //arg1 => {name:'a',id:'5'}
    var query=req.query;//参数
    request({
        url: pro.serveraddr+'/report/caractionlist',
        method: "POST",
        qs: arg
    }, function(error, response, body) {
        if (!error && response.statusCode == 200) {
            var data=JSON.parse(body);
            if(data && data.success){
                res.json(data);
            }else {
                console.log("error= " + data.msg );
                res.json(data.msg);
            }



        }
    });
});
router.get('/fencelist', function(req, res, next) {
    auth.checkAuth(req, res, next);
    //
    // var data={"msg":"","recordsFiltered":3,"success":true,"obj":null,"draw":1,
    //     "rows":[
    //         {"id":1,"baseCarNo":"鲁xiaofan","deptName":0.0,"userName":"刘明","runTime":"公司仓库","runNum":"驶入","runMile":"4","lineNum":"2016-06-24 10:34:55"},
    //         {"id":2,"baseCarNo":"鲁xiaofan1","deptName":0.0,"userName":"张三","runTime":"固定送货区域","runNum":"驶出","runMile":"2","lineNum":"2016-06-24 16:34:55"}
    //     ],
    //     "recordsTotal":3};
    // res.json(data);




    var pathname = url.parse(req.url).pathname;  //pathname => list

    var arg = url.parse(req.url, true).query;   //arg1 => {name:'a',id:'5'}
    var query=req.query;//参数
    request({
        url: pro.serveraddr+'/report/fencelist',
        method: "POST",
        qs: arg
    }, function(error, response, body) {
        if (!error && response.statusCode == 200) {
            var data=JSON.parse(body);
            if(data && data.success){
                res.json(data);
            }else {
                console.log("error= " + data.msg );
                res.json(data.msg);
            }



        }
    });
});
router.get('/businesslist', function(req, res, next) {

    auth.checkAuth(req, res, next);

    var data={"msg":"","recordsFiltered":3,"success":true,"obj":null,"draw":1,
        "rows":[
            {"id":1,"baseCarNo":"鲁xiaofan","deptName":"刘明","userName":"99867801","runTime":"1337899012377","runNum":"2015-06-24 10:34:55","runMile":"2016-06-28 10:34:55"},
            {"id":2,"baseCarNo":"鲁xiaofan1","deptName":"张三","userName":"99867802","runTime":"1337899012378","runNum":"2015-06-24 16:34:55","runMile":"2016-06-28 10:34:55"}
        ],
        "recordsTotal":3};
    res.json(data);
    // var pathname = url.parse(req.url).pathname;  //pathname => list
    //
    // var arg = url.parse(req.url, true).query;   //arg1 => {name:'a',id:'5'}
    // var query=req.query;//参数
    // request({
    //     url: pro.serveraddr+'/report/business',
    //     method: "POST",
    //     qs: arg
    // }, function(error, response, body) {
    //     if (!error && response.statusCode == 200) {
    //         var data=JSON.parse(body);
    //         if(data && data.success){
    //             res.json(data);
    //         }else {
    //             console.log("error= " + data.msg );
    //             res.json(data.msg);
    //         }
    //
    //
    //
    //     }
    // });
});

// 区域统计
router.get('/caractionchart', function(req, res, next) {
    auth.checkAuth(req, res, next);
    var pathname = url.parse(req.url).pathname;  //pathname => list

    var arg = url.parse(req.url, true).query;   //arg1 => {name:'a',id:'5'}
    var query=req.query;//参数
    request({
        url: pro.serveraddr+'/report/caractionchart',
        method: "POST",
        qs: arg
    }, function(error, response, body) {
        if (!error && response.statusCode == 200) {
            var data=JSON.parse(body);
            if(data ){
                res.json(data);
            }else {
                console.log("error= " + data.msg );
                res.json(data.msg);
            }



        }
    });
});
// 工作时段统计图表
router.get('/carworktimechart', function(req, res, next) {
    auth.checkAuth(req, res, next);
    var pathname = url.parse(req.url).pathname;  //pathname => list

    var arg = url.parse(req.url, true).query;   //arg1 => {name:'a',id:'5'}
    var query=req.query;//参数
    request({
        url: pro.serveraddr+'/report/carworktimechart',
        method: "POST",
        qs: arg
    }, function(error, response, body) {
        if (!error && response.statusCode == 200) {
            var data=JSON.parse(body);
            if(data ){
                res.json(data);
            }else {
                console.log("error= " + data.msg );
                res.json(data.msg);
            }



        }
    });
});
// 报警统计
router.get('/warningchart', function(req, res, next) {
    auth.checkAuth(req, res, next);
    var pathname = url.parse(req.url).pathname;  //pathname => list

    var arg = url.parse(req.url, true).query;   //arg1 => {name:'a',id:'5'}
    var query=req.query;//参数
    request({
        url: pro.serveraddr+'/report/warningchart',
        method: "POST",
        qs: arg
    }, function(error, response, body) {
        if (!error && response.statusCode == 200) {
            var data=JSON.parse(body);
            if(data ){
                res.json(data);
            }else {
                console.log("error= " + data.msg );
                res.json(data.msg);
            }



        }
    });
});
// 统计大数据
router.get('/queryTotalData', function(req, res, next) {
    auth.checkAuth(req, res, next);
    var pathname = url.parse(req.url).pathname;  //pathname => list

    var arg = url.parse(req.url, true).query;   //arg1 => {name:'a',id:'5'}
    var query=req.query;//参数
    var sid = auth.getSessionID(req, res, next);
    arg.sid=sid;
    request({
        url: pro.serveraddr+'/report/queryTotalData',
        method: "POST",
        qs: arg
    }, function(error, response, body) {
        if (!error && response.statusCode == 200) {
            var data=JSON.parse(body);
            if(data ){
                res.json(data);
            }else {
                console.log("error= " + data.msg );
                res.json(data.msg);
            }



        }
    });
});
// 统计大数据图表
router.get('/totalChart', function(req, res, next) {
    auth.checkAuth(req, res, next);
    var pathname = url.parse(req.url).pathname;  //pathname => list

    var arg = url.parse(req.url, true).query;   //arg1 => {name:'a',id:'5'}
    var query=req.query;//参数
    var sid = auth.getSessionID(req, res, next);
    arg.sid=sid;
    request({
        url: pro.serveraddr+'/report/totalChart',
        method: "POST",
        qs: arg
    }, function(error, response, body) {
        if (!error && response.statusCode == 200) {
            var data=JSON.parse(body);
            if(data ){
                res.json(data);
            }else {
                console.log("error= " + data.msg );
                res.json(data.msg);
            }



        }
    });
});
// 统计大数据图表下方的数据
router.get('/queryTotalMonthData', function(req, res, next) {
    auth.checkAuth(req, res, next);
    var pathname = url.parse(req.url).pathname;  //pathname => list

    var arg = url.parse(req.url, true).query;   //arg1 => {name:'a',id:'5'}
    var query=req.query;//参数
    request({
        url: pro.serveraddr+'/report/queryTotalMonthData',
        method: "POST",
        qs: arg
    }, function(error, response, body) {
        if (!error && response.statusCode == 200) {
            var data=JSON.parse(body);
            if(data ){
                res.json(data);
            }else {
                console.log("error= " + data.msg );
                res.json(data.msg);
            }



        }
    });
});
router.get('/outLinelist', function(req, res, next) {
    auth.checkAuth(req, res, next);
    var pathname = url.parse(req.url).pathname;  //pathname => list

    var arg = url.parse(req.url, true).query;   //arg1 => {name:'a',id:'5'}
    var query=req.query;//参数
    request({
        url: pro.serveraddr+'/baseCar/outLinelist',
        method: "POST",
        qs: arg
    }, function(error, response, body) {
        if (!error && response.statusCode == 200) {
            var data=JSON.parse(body);
            if(data ){
                res.json(data);
            }else {
                console.log("error= " + data.msg );
                res.json(data.msg);
            }



        }
    });
});
module.exports = router;
